package cn.itcast.n4.deadlock;

import cn.itcast.n2.util.Sleeper;
import lombok.extern.slf4j.Slf4j;

@Slf4j(topic = "c.TestDeadLock")
public class TestDeadLock {

    static Object A = new Object();
    static Object B = new Object();

    public static void main(String[] args) {
        new Thread(() -> {
            synchronized (A){
                log.debug("哎，我拿到锁了，我就是不干活。。。");
                Sleeper.sleep(2);
                synchronized (B){
                    log.debug("我现在才拿到锁啊。。。。");
                }
            }
        },"大狗子").start();

        new Thread(() -> {
            synchronized (B){
                log.debug("哎，我拿到锁了，我就是不干活。。。");
//                Sleeper.sleep(2);
                synchronized (A){
                    log.debug("我现在才拿到锁啊。。。。");
                }
            }
        },"二狗子").start();


    }
}
